package com.test;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*****
 * 
 *使用注解的方法  @WebServlet  
 *value 访问路径 
 *loadOnStartup表示服务器启动加载这个servlet并且执行init的方法
 */
@WebServlet(value="/demo2",loadOnStartup=1)
public class ServletDemo2 extends HttpServlet {
   @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	 //解决中文乱码问题
	    resp.setCharacterEncoding("utf-8");// 内容编码，防止出现中文乱码
		resp.setContentType("text/html;charset=utf-8");		//向浏览器输出内容
		resp.getWriter().write("ServletDemo2.......................");
    }
   
   @Override
	public void init() throws ServletException {
		 System.out.println("ServletDemo2  init");
	}
}
